package mode.bridgeMode09;

/**
 * 09桥接模式 pattern
 * 定义 ： 将抽象部分与他的实现部分分离，使它们都可以独立的变化
 */
public class BridgePatternDemo {
    public static void main(String[] args) {
        AudiCar audi = new AudiCar(new AutoEngine());
        audi.running();

        // 这里 可以灵活的配置 abstract engine ,
        BMWCar BMW = new BMWCar(new AutoEngine());
        BMW.running();



        BenZCar benZ = new BenZCar(new ManualEngine());
        benZ.running();

    }

    //  自动挡汽车 ---- AudiZCar *****
    //  自动挡汽车BMWCar.....
    //  手动挡汽车BenZCar *****

}


abstract class AbstractEngine {
    public abstract  String engine();
}


class AutoEngine extends AbstractEngine {
    @Override
    public String engine() {
        return "自动挡汽车";
    }
}


class ManualEngine extends AbstractEngine {
    @Override
    public String engine() {
        return "手动挡汽车";
    }
}

abstract class AbstractCar{
    public AbstractEngine absEngine;

    public AbstractCar(AbstractEngine abstractEngine){
        this.absEngine = abstractEngine;
    }

    public abstract void running();

}

class BMWCar extends AbstractCar{

    public BMWCar(AbstractEngine abstractEngine){
        super(abstractEngine);
    }

    @Override
    public void running() {
        System.out.println(absEngine.engine() + "BMWCar.....");
    }
}


class BenZCar extends AbstractCar{

    public BenZCar(AbstractEngine abstractEngine){
        super(abstractEngine);
    }

    @Override
    public void running() {
        System.out.println(absEngine.engine() + "BenZCar ***** ");
    }
}




class AudiCar extends AbstractCar{

    public AudiCar(AbstractEngine abstractEngine){
        super(abstractEngine);
    }

    @Override
    public void running() {
        System.out.println(absEngine.engine() + " ---- AudiZCar ***** ");
    }
}






















